package com.csdj.t309springboot.kaoshi.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csdj.t309springboot.kaoshi.entity.Paper;
import com.csdj.t309springboot.kaoshi.entity.PaperExample;
import com.csdj.t309springboot.kaoshi.entity.User;
import com.csdj.t309springboot.kaoshi.entity.UserExample;
import com.csdj.t309springboot.kaoshi.mapper.PaperMapper;
import com.csdj.t309springboot.kaoshi.utils.SecurityUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class PaperService {
    @Resource
    private PaperMapper mapper;

    public List<Paper> getAllPaper(){
//        return mapper.selectByExample(new PaperExample());
        //new QueryWrapper()
        return mapper.selectList(new QueryWrapper() );
    }

    public List<Paper> getAllPaperByTitleOrTypeCode(String title,String typeCode){
        System.out.println("String title="+title+",String typeCode="+typeCode);
//        UserExample userExample = new UserExample();
//        userExample.createCriteria().andUserCodeEqualTo(account)
//                .andUserPasswordEqualTo(SecurityUtils.md5Hex(password));
//        PaperExample example = new PaperExample();
//        example.createCriteria().andTitleLike(title).andTypeCodeEqualTo(typeCode);

        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("type_code",typeCode);
        wrapper.like("title",title);

        return mapper.selectList(wrapper);
    }

    public int insert(Paper paper) {
//        return mapper.insert(paper);
        return mapper.insert(paper);
    }

    public List<Paper> checkTitle(String title){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("title",title);

        return mapper.selectList(wrapper);
    }

    public  int deleteByPrimaryKey(int id){

        return mapper.deleteByPrimaryKey(id);
    }

//    /**
//     * 分页
//     * @return
//     */
//    public IPage<User> selectPage(int pageNum, Integer size){
//        Page<Paper> page = new Page<Paper>(pageNum,null);
//        return mapper.selectPage(page,null);
//    }


}
